﻿<Window x:Class="Black.Minecraft.Editor.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:bh="clr-namespace:Black.Minecraft.Editor.Behaviors"
        xmlns:dv="clr-namespace:Black.Minecraft.Editor.Views.DataViews"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:vm="clr-namespace:Black.Minecraft.Editor.ViewModels"
        x:Name="root"
        Title="{Binding Title}"
        Width="968"
        Height="546"
        DataContext="{Binding Source={x:Static vm:MainViewModel.Instance}}"
        ResizeMode="NoResize"
        WindowStartupLocation="CenterScreen">

    <!--  Root de la page  -->

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!--  VisualState  -->

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualStateGroup.Transitions>
                    <VisualTransition From="Normal" To="Opened">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PopupGrid" Storyboard.TargetProperty="(UIElement.Visibility)">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PopupContainer" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
                                <DiscreteDoubleKeyFrame KeyTime="0" Value="0.8" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.200" Value="1" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PopupContainer" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
                                <DiscreteDoubleKeyFrame KeyTime="0" Value="0.8" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.200" Value="1" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PopupGrid" Storyboard.TargetProperty="(UIElement.Opacity)">
                                <DiscreteDoubleKeyFrame KeyTime="0" Value="0" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.100" Value="1" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualTransition>
                    <VisualTransition From="Opened" To="Normal">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PopupGrid" Storyboard.TargetProperty="(UIElement.Visibility)">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.200" Value="{x:Static Visibility.Collapsed}" />
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PopupContainer" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
                                <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.200" Value="0.8" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PopupContainer" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
                                <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.200" Value="0.8" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PopupGrid" Storyboard.TargetProperty="(UIElement.Opacity)">
                                <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                                <DiscreteDoubleKeyFrame KeyTime="0:0:0.100" Value="1" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.200" Value="0" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualTransition>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Normal" />
                <VisualState x:Name="Opened">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PopupGrid" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PopupContainer" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
                            <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PopupContainer" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
                            <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <!--  Behaviors  -->

        <i:Interaction.Behaviors>
            <bh:VisualStateBehavior GoToElementState="{Binding PopupState}" />
            <bh:EventToCommandBehavior Command="{Binding LoadedCommand}" Event="Loaded" />
        </i:Interaction.Behaviors>

        <!--  Menu de l'application  -->

        <Menu Grid.Row="0"
              Grid.Column="0"
              Grid.ColumnSpan="2">
            <MenuItem Header="_File">
                <MenuItem Command="{Binding MenuOpenCommand}" Header="_Open..." />
                <MenuItem Header="Open _local save"
                          IsEnabled="{Binding IsMenuOpenSaveEnable}"
                          ItemsSource="{Binding MinecraftLocalSaves}">
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="Command" Value="{Binding ElementName=root, Path=DataContext.MenuOpenSaveCommand}" />
                            <Setter Property="CommandParameter" Value="{Binding}" />
                        </Style>
                    </MenuItem.ItemContainerStyle>
                    <MenuItem.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" />
                        </DataTemplate>
                    </MenuItem.ItemTemplate>
                </MenuItem>
                <MenuItem Command="{Binding MenuCloseCommand}"
                          Header="_Close"
                          IsEnabled="{Binding IsMenuCloseEnable}" />
                <Separator />
                <MenuItem Command="{Binding MenuSaveCommand}"
                          Header="_Save"
                          IsEnabled="{Binding IsMenuSaveEnable}" />
                <MenuItem Command="{Binding MenuSaveAsCommand}"
                          Header="Save As..."
                          IsEnabled="{Binding IsMenuSaveAsEnable}" />
                <Separator />
                <MenuItem Command="{Binding MenuExitCommand}" Header="_Exit" />
            </MenuItem>
            <MenuItem Header="_Settings">
                <MenuItem Command="{Binding MenuOptionsCommand}" Header="_Options..." />
            </MenuItem>
            <MenuItem Header="_Help">
                <MenuItem Command="{Binding MenuAboutCommand}" Header="_About..." />
            </MenuItem>
        </Menu>

        <!--  Message pour chargement  -->

        <TextBlock Grid.Row="0"
                   Grid.RowSpan="3"
                   Grid.Column="0"
                   Grid.ColumnSpan="2"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Foreground="Black"
                   TextAlignment="Center"
                   Visibility="{Binding IsOpen,
                                        Converter={StaticResource BoolToVisibilityConverter},
                                        ConverterParameter=invert}">
            <Run FontWeight="Bold" Text="Welcome to Black Minecraft Editor" />
            <LineBreak />
            <LineBreak />
            <Run Text="Please select a file to edit" />
        </TextBlock>

        <!--  Informations sur la partie  -->

        <GroupBox Grid.Row="1"
                  Grid.Column="0"
                  Grid.ColumnSpan="2"
                  Margin="4"
                  FontWeight="Bold"
                  Foreground="Blue"
                  Header="Game Information"
                  Visibility="{Binding IsOpen,
                                       Converter={StaticResource BoolToVisibilityConverter}}">
            <Grid>
                <ContentControl Content="{Binding GameInformation}" Visibility="{Binding IsServerGame, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=invert}" />
                <TextBlock Margin="4,20,4,20"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           FontWeight="Normal"
                           Foreground="Black"
                           Text="This is a player file from a server definition, no modification availaible."
                           Visibility="{Binding IsServerGame,
                                                Converter={StaticResource BoolToVisibilityConverter}}" />
            </Grid>
        </GroupBox>

        <!--  Information sur le joueur  -->

        <GroupBox Grid.Row="2"
                  Grid.Column="0"
                  Margin="4"
                  FontWeight="Bold"
                  Foreground="Green"
                  Header="Player Information"
                  Visibility="{Binding IsOpen,
                                       Converter={StaticResource BoolToVisibilityConverter}}">
            <ContentControl Content="{Binding PlayerInformation}" />
        </GroupBox>

        <!--  Inventaire  -->

        <GroupBox Grid.Row="2"
                  Grid.Column="1"
                  Margin="4"
                  FontWeight="Bold"
                  Foreground="Orange"
                  Header="Inventory"
                  Visibility="{Binding IsOpen,
                                       Converter={StaticResource BoolToVisibilityConverter}}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <!--  Liste des objets  -->

                <StackPanel Grid.Row="2"
                            Grid.Column="0"
                            Width="300"
                            Height="362"
                            Margin="4">
                    <StackPanel Margin="0,0,0,4" Orientation="Horizontal">
                        <TextBlock Margin="0,0,10,0"
                                   Foreground="Black"
                                   Text="Search :" />
                        <TextBox x:Name="SearchBox"
                                 Width="220"
                                 BorderBrush="Gray"
                                 BorderThickness="1">
                            <i:Interaction.Behaviors>
                                <bh:TextChangedBehavior Command="{Binding SearchChangedCommand}" CommandParameter="{Binding ElementName=SearchBox, Path=Text}" />
                            </i:Interaction.Behaviors>
                        </TextBox>
                        <Button Margin="8,0,0,0"
                                Click="OnClearSearchClick"
                                Command="{Binding ClearSearchCommand}">
                            <Button.ToolTip>
                                <TextBlock Text="Clear search" />
                            </Button.ToolTip>
                            <Image Width="14"
                                   Height="14"
                                   Source="/Assets/Delete.png"
                                   Stretch="Fill" />
                        </Button>
                    </StackPanel>
                    <ListBox x:Name="ItemsList"
                             Width="300"
                             Height="340"
                             Background="#EEEEEE"
                             FontWeight="Normal"
                             ItemsSource="{Binding ItemsDefinition}"
                             PreviewMouseLeftButtonDown="OnItemsListPreviewMouseLeftButtonDown"
                             PreviewMouseMove="OnItemsListPreviewMouseMove" />
                </StackPanel>

                <ContentControl Grid.Column="1"
                                Width="362"
                                Height="342"
                                Margin="5"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Content="{Binding Inventory}" />
            </Grid>
        </GroupBox>

        <!--  Popup  -->

        <Grid x:Name="PopupGrid"
              Grid.Row="0"
              Grid.RowSpan="3"
              Grid.Column="0"
              Grid.ColumnSpan="2"
              Background="#22000000"
              Visibility="Collapsed">
            <ContentControl x:Name="PopupContainer"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Background="White"
                            Content="{Binding Popup}"
                            RenderTransformOrigin="0.5,0.5">
                <ContentControl.RenderTransform>
                    <ScaleTransform />
                </ContentControl.RenderTransform>
            </ContentControl>
        </Grid>

    </Grid>

</Window>
